home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / TextStream / TextStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.2 KB  |  546 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class TextStream extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    // $FF: renamed from: b java.awt.Graphics
  20.    private Graphics field_0;
  21.    private Image buffer;
  22.    private Image backImage;
  23.    private boolean loaded;
  24.    private boolean isBackImage = false;
  25.    private boolean paintable = false;
  26.    private boolean move = true;
  27.    private boolean firstime = true;
  28.    // $FF: renamed from: on boolean
  29.    private boolean field_1 = true;
  30.    private boolean make_pause2 = false;
  31.    // $FF: renamed from: wi int
  32.    private int field_2;
  33.    // $FF: renamed from: he int
  34.    private int field_3;
  35.    private int decx;
  36.    private int decy;
  37.    private int pause;
  38.    private int pause2;
  39.    private int text_height;
  40.    private int height_step;
  41.    private int n_ligne;
  42.    // $FF: renamed from: l int
  43.    private int field_4;
  44.    private int[] index;
  45.    private Color textColor;
  46.    private String backImageName;
  47.    private String[] text;
  48.    private String big_text;
  49.    private String letter;
  50.    private Color backColor;
  51.    // $FF: renamed from: fm java.awt.FontMetrics
  52.    private FontMetrics field_5;
  53.    private int wiBack;
  54.    private int heBack;
  55.    private Color enterBackColor;
  56.    private Color enterTextColor;
  57.    private AudioClip sound;
  58.    private AudioClip clicSound;
  59.    private AudioClip enterSound;
  60.    private boolean loopSound;
  61.    private String link;
  62.    private String statusBarText;
  63.    private int pause3;
  64.    private boolean change = true;
  65.  
  66.    public String getAppletInfo() {
  67.       return "Name: TextStream\r\nAuthor: Taiji Software\r\n";
  68.    }
  69.  
  70.    public TextStream() {
  71.       this.move = true;
  72.       this.pause = 100;
  73.       this.pause2 = 500;
  74.       this.text_height = 10;
  75.       this.decx = 0;
  76.       this.decy = 0;
  77.       this.pause3 = 0;
  78.       ((Component)this).addMouseListener(this);
  79.    }
  80.  
  81.    public void register() {
  82.       try {
  83.          URL u = new URL("http://www.taijisoftware.com");
  84.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  85.       } catch (Exception e) {
  86.          System.out.println(e);
  87.          this.stop();
  88.       }
  89.    }
  90.  
  91.    public void init() {
  92.       String codeBase = null;
  93.  
  94.       try {
  95.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  96.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  97.          codeBase = codeBase.toUpperCase();
  98.       } catch (Exception var9) {
  99.       }
  100.  
  101.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  102.          String regCode = ((Applet)this).getParameter("registration_code");
  103.          if (regCode == null) {
  104.             regCode = ((Applet)this).getParameter("reg_domain");
  105.             if (regCode == null) {
  106.                this.register();
  107.             } else {
  108.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  109.                   codeBase = "WWW." + codeBase;
  110.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  111.                   codeBase = codeBase.substring(4);
  112.                }
  113.  
  114.                char[] chars = new char[codeBase.length()];
  115.                codeBase.getChars(0, codeBase.length(), chars, 0);
  116.                String key = new String("haricot");
  117.                char[] chars2 = new char[key.length()];
  118.                key.getChars(0, key.length(), chars2, 0);
  119.  
  120.                for(int i = 0; i < codeBase.length(); ++i) {
  121.                   int j;
  122.                   if (i >= key.length()) {
  123.                      j = i - key.length() * (i / key.length());
  124.                   } else {
  125.                      j = i;
  126.                   }
  127.  
  128.                   chars[i] += chars2[j];
  129.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  130.                }
  131.  
  132.                String res = new String(chars);
  133.                if (!res.equalsIgnoreCase(regCode)) {
  134.                   this.register();
  135.                }
  136.             }
  137.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  138.             this.register();
  139.          }
  140.       }
  141.  
  142.       this.getParameters();
  143.       if (this.sound != null) {
  144.          if (this.loopSound) {
  145.             this.sound.loop();
  146.             return;
  147.          }
  148.  
  149.          this.sound.play();
  150.       }
  151.  
  152.    }
  153.  
  154.    public void getParameters() {
  155.       String s = ((Applet)this).getParameter("pause");
  156.       if (s != null) {
  157.          this.pause = Integer.parseInt(s);
  158.       }
  159.  
  160.       this.field_2 = ((Component)this).getSize().width;
  161.       this.field_3 = ((Component)this).getSize().height;
  162.       s = ((Applet)this).getParameter("pause2");
  163.       if (s != null) {
  164.          this.pause2 = Integer.parseInt(s);
  165.       }
  166.  
  167.       this.big_text = ((Applet)this).getParameter("text");
  168.       if (this.big_text == null) {
  169.          this.big_text = "no text !!";
  170.       }
  171.  
  172.       this.textColor = this.getColor("text_color");
  173.       this.backColor = this.getColor("background_color");
  174.       ((Component)this).setBackground(this.backColor);
  175.       s = ((Applet)this).getParameter("text_height");
  176.       if (s != null) {
  177.          this.text_height = Integer.parseInt(s);
  178.       }
  179.  
  180.       s = ((Applet)this).getParameter("width_shift");
  181.       if (s != null) {
  182.          this.decx = Integer.parseInt(s);
  183.       }
  184.  
  185.       s = ((Applet)this).getParameter("height_shift");
  186.       if (s != null) {
  187.          this.decy = Integer.parseInt(s);
  188.       }
  189.  
  190.       this.backImageName = ((Applet)this).getParameter("background_image");
  191.       if (this.backImageName != null) {
  192.          this.isBackImage = true;
  193.       }
  194.  
  195.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  196.       s = ((Applet)this).getParameter("sound_name");
  197.       if (s != null) {
  198.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  199.       }
  200.  
  201.       s = ((Applet)this).getParameter("loop_sound");
  202.       if (s != null) {
  203.          if (s.equals("yes")) {
  204.             this.loopSound = true;
  205.          } else {
  206.             this.loopSound = false;
  207.          }
  208.       }
  209.  
  210.       s = ((Applet)this).getParameter("clic_sound_name");
  211.       if (s != null) {
  212.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  213.       }
  214.  
  215.       s = ((Applet)this).getParameter("enter_sound_name");
  216.       if (s != null) {
  217.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  218.       }
  219.  
  220.       this.link = ((Applet)this).getParameter("link");
  221.       s = ((Applet)this).getParameter("pause3");
  222.       if (s != null) {
  223.          this.pause3 = Integer.parseInt(s);
  224.       }
  225.  
  226.    }
  227.  
  228.    public Color getColor(String param) {
  229.       String s = ((Applet)this).getParameter(param);
  230.       if (s != null) {
  231.          if (s.substring(0, 1).equals("#")) {
  232.             s = s.substring(1);
  233.             int i = Integer.parseInt(s, 16);
  234.             return new Color(i);
  235.          } else {
  236.             return null;
  237.          }
  238.       } else {
  239.          return null;
  240.       }
  241.    }
  242.  
  243.    public final void paint(Graphics g) {
  244.       if (this.paintable) {
  245.          if (this.change) {
  246.             this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  247.          }
  248.  
  249.          if (this.isBackImage & this.loaded) {
  250.             this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  251.          }
  252.  
  253.          this.letter = this.text[this.n_ligne].substring(0, this.field_4 + 1);
  254.  
  255.          for(int i = 0; i < this.n_ligne; ++i) {
  256.             this.field_0.drawString(this.text[i], this.decx, this.decy + i * this.text_height);
  257.          }
  258.  
  259.          this.field_0.drawString(this.letter, this.decx, this.decy + this.n_ligne * this.text_height);
  260.          if (this.field_4 >= this.text[this.n_ligne].length() - 1) {
  261.             ++this.n_ligne;
  262.             if (this.n_ligne >= this.text.length) {
  263.                this.n_ligne = 0;
  264.                this.change = true;
  265.             }
  266.  
  267.             this.field_4 = 0;
  268.          } else {
  269.             ++this.field_4;
  270.          }
  271.  
  272.          g.drawImage(this.buffer, 0, 0, this);
  273.          if (this.field_4 == 0) {
  274.             try {
  275.                Thread.sleep((long)this.pause2);
  276.             } catch (InterruptedException var5) {
  277.                this.stop();
  278.             }
  279.  
  280.             if (this.n_ligne == 0) {
  281.                if (this.pause3 == -1) {
  282.                   this.change = false;
  283.                   return;
  284.                }
  285.  
  286.                try {
  287.                   Thread.sleep((long)this.pause3);
  288.                } catch (InterruptedException var4) {
  289.                   this.stop();
  290.                }
  291.  
  292.                if (this.change) {
  293.                   this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  294.                }
  295.  
  296.                if (this.isBackImage & this.loaded) {
  297.                   this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  298.                }
  299.  
  300.                g.drawImage(this.buffer, 0, 0, this);
  301.  
  302.                try {
  303.                   Thread.currentThread();
  304.                   Thread.sleep((long)this.pause2);
  305.                   return;
  306.                } catch (InterruptedException var3) {
  307.                   this.stop();
  308.                   return;
  309.                }
  310.             }
  311.          }
  312.       }
  313.  
  314.    }
  315.  
  316.    public final void update(Graphics g) {
  317.       this.paint(g);
  318.    }
  319.  
  320.    public void start() {
  321.       this.move = true;
  322.       if (this.thread == null) {
  323.          this.thread = new Thread(this);
  324.          this.thread.start();
  325.       }
  326.  
  327.    }
  328.  
  329.    public void stop() {
  330.       if (this.thread != null) {
  331.          this.move = false;
  332.          this.thread = null;
  333.       }
  334.  
  335.       if (this.sound != null) {
  336.          this.sound.stop();
  337.       }
  338.  
  339.    }
  340.  
  341.    public void run() {
  342.       if (this.firstime) {
  343.          if (this.isBackImage) {
  344.             MediaTracker tracker = new MediaTracker(this);
  345.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  346.             tracker.addImage(this.backImage, 0);
  347.  
  348.             try {
  349.                tracker.waitForAll();
  350.                this.loaded = !tracker.isErrorAny();
  351.             } catch (InterruptedException var5) {
  352.                this.stop();
  353.             }
  354.  
  355.             if (!this.loaded) {
  356.                this.stop();
  357.                return;
  358.             }
  359.          }
  360.  
  361.          if (this.isBackImage) {
  362.             this.wiBack = this.backImage.getWidth(this);
  363.             this.heBack = this.backImage.getHeight(this);
  364.          }
  365.  
  366.          this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  367.          this.field_0 = this.buffer.getGraphics();
  368.          String fontName = ((Applet)this).getParameter("text_font");
  369.          if (fontName == null) {
  370.             fontName = "TimesRoman";
  371.          }
  372.  
  373.          int style = 1;
  374.          String s = ((Applet)this).getParameter("text_style");
  375.          if (s != null) {
  376.             if (s.equals("bold")) {
  377.                style = 1;
  378.             } else if (s.equals("italic")) {
  379.                style = 2;
  380.             } else if (s.equals("bold_italic")) {
  381.                style = 3;
  382.             } else {
  383.                style = 0;
  384.             }
  385.          }
  386.  
  387.          this.field_0.setFont(new Font(fontName, style, this.text_height));
  388.          this.field_5 = this.field_0.getFontMetrics();
  389.          this.field_0.setColor(this.textColor);
  390.          this.paintable = true;
  391.          this.firstime = false;
  392.       }
  393.  
  394.       int c = 0;
  395.  
  396.       int m;
  397.       for(m = 0; (c = this.big_text.indexOf("#", c)) != -1; ++m) {
  398.          ++c;
  399.       }
  400.  
  401.       if (m != 0) {
  402.          this.index = new int[m];
  403.          this.text = new String[m + 1];
  404.  
  405.          for(m = 0; (c = this.big_text.indexOf("#", c)) != -1; ++m) {
  406.             this.index[m] = c;
  407.             if (m == 0) {
  408.                this.text[m] = this.big_text.substring(0, this.index[0]);
  409.             } else {
  410.                this.text[m] = this.big_text.substring(this.index[m - 1] + 1, this.index[m]);
  411.             }
  412.  
  413.             if (this.text[m].equals("")) {
  414.                this.text[m] = " ";
  415.             }
  416.  
  417.             ++c;
  418.          }
  419.  
  420.          this.text[m] = this.big_text.substring(this.index[m - 1] + 1);
  421.          this.n_ligne = 0;
  422.       } else {
  423.          this.text = new String[1];
  424.          this.text[0] = this.big_text;
  425.       }
  426.  
  427.       this.field_4 = 0;
  428.  
  429.       while(this.move) {
  430.          while(this.field_1) {
  431.             ((Component)this).repaint();
  432.  
  433.             try {
  434.                Thread.sleep((long)this.pause);
  435.             } catch (InterruptedException var6) {
  436.                this.stop();
  437.             }
  438.  
  439.             if (!this.field_1) {
  440.             }
  441.          }
  442.  
  443.          try {
  444.             Thread.sleep(100L);
  445.          } catch (InterruptedException var4) {
  446.             this.stop();
  447.          }
  448.       }
  449.  
  450.    }
  451.  
  452.    public URL giveURL(String url) {
  453.       try {
  454.          if (url.toUpperCase().startsWith("HTTP")) {
  455.             return new URL(url);
  456.          } else if (url.toUpperCase().startsWith("FTP")) {
  457.             int p = url.indexOf(":");
  458.             int p2 = url.indexOf(":", p + 1);
  459.             if (p2 != -1) {
  460.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  461.             }
  462.  
  463.             p = url.indexOf("%40");
  464.             if (p != -1) {
  465.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  466.             }
  467.  
  468.             return new URL(url);
  469.          } else {
  470.             return new URL(((Applet)this).getCodeBase(), url);
  471.          }
  472.       } catch (MalformedURLException e) {
  473.          System.out.println(e);
  474.          return null;
  475.       }
  476.    }
  477.  
  478.    public void mouseClicked(MouseEvent e) {
  479.    }
  480.  
  481.    public void mouseEntered(MouseEvent e) {
  482.       if (this.enterBackColor != null) {
  483.          ((Component)this).setBackground(this.enterBackColor);
  484.          ((Component)this).repaint();
  485.       }
  486.  
  487.       if (this.enterTextColor != null) {
  488.          if (this.field_0 != null) {
  489.             this.field_0.setColor(this.enterTextColor);
  490.          }
  491.  
  492.          ((Component)this).repaint();
  493.       }
  494.  
  495.       if (this.statusBarText != null) {
  496.          ((Applet)this).showStatus(this.statusBarText);
  497.       }
  498.  
  499.       if (this.enterSound != null) {
  500.          this.enterSound.play();
  501.       }
  502.  
  503.       if (this.link != null) {
  504.          ((Component)this).setCursor(new Cursor(12));
  505.       }
  506.  
  507.    }
  508.  
  509.    public void mouseExited(MouseEvent e) {
  510.       if (this.enterBackColor != null) {
  511.          ((Component)this).setBackground(this.backColor);
  512.          ((Component)this).repaint();
  513.       }
  514.  
  515.       if (this.enterTextColor != null) {
  516.          this.field_0.setColor(this.textColor);
  517.          ((Component)this).repaint();
  518.       }
  519.  
  520.       if (this.link != null) {
  521.          ((Component)this).setCursor(new Cursor(0));
  522.       }
  523.  
  524.    }
  525.  
  526.    public void mousePressed(MouseEvent e) {
  527.       if (this.clicSound != null) {
  528.          this.clicSound.play();
  529.       }
  530.  
  531.       if (this.link != null) {
  532.          String target = ((Applet)this).getParameter("target");
  533.          if (target == null) {
  534.             target = "_blank";
  535.          }
  536.  
  537.          URL u = this.giveURL(this.link);
  538.          ((Applet)this).getAppletContext().showDocument(u, target);
  539.       }
  540.  
  541.    }
  542.  
  543.    public void mouseReleased(MouseEvent e) {
  544.    }
  545. }
  546.